﻿using System;
using System.Collections.Generic;
using System.Text;
using HZU.ZP.Data.Interfaces;
using HZU.ZP.Domain.IService;
using HZU.ZP.Domain.Model;
using HZU.ZP.Domain.ServiceImpl.Mappers;

namespace HZU.ZP.Domain.ServiceImpl.PCSvc
{
    public class ApplyRecordService : IApplyRecordService
    {
        private ApplyRecordMapper _mapper = new ApplyRecordMapper();
        private IApplyRecordDao _sqlData;
        public ApplyRecordService(IApplyRecordDao sqlData)
        {
            _sqlData = sqlData;
        }

        public bool Add(ApplyRecord applyRecord)
        {
            var applyRecordDao = _mapper.MapToDao(applyRecord);
            _sqlData.Add(applyRecordDao);
            return true;
        }

        public int GetAppCount(int applicantId, int processing)
        {
            return _sqlData.GetAppCount(applicantId, processing);
        }

        public ApplyRecord GetByAppIdAndId(int applicantId, int positionId)
        {
            return _mapper.MapToDomain(_sqlData.Get(applicantId, positionId));
        }

        public IList<ApplyRecord> GetByApplicant(int applicantId, int processing, int pageIndex)
        {
            var applyRecordDaoList = _sqlData.GetByApplicant(applicantId, processing, pageIndex);
            return _mapper.MapToDomainList(applyRecordDaoList);
        }

        public ApplyRecord GetByComAndId(int companyId, int positionId)
        {
            return _mapper.MapToDomain(_sqlData.GetByComAndId(companyId,positionId));
        }

        public IList<ApplyRecord> GetByCompany(int companyId, int processing, int pageIndex)
        {
            var applyRecordDaoList = _sqlData.GetByApplicant(companyId, processing, pageIndex);
            return _mapper.MapToDomainList(applyRecordDaoList);
        }

        public ApplyRecord GetById(int id)
        {
            return _mapper.MapToDomain(_sqlData.Get(id));
        }

        public int GetComCount(int companyId, int processing)
        {
            return _sqlData.GetComCount(companyId, processing);
        }

        public bool Update(ApplyRecord applyRecord)
        {
            var applyRecordDao = _mapper.MapToDao(applyRecord);
            _sqlData.Update(applyRecordDao);
            return true;
        }
    }
}
